//
//  AppDelegate.m
//  TravelDiary
//
//  Created by YDB MAC on 15/11/11.
//  Copyright © 2015年 YDB MAC. All rights reserved.
//

#import "AppDelegate.h"
#import "LYYTabBarViewController.h"
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import "UserLocationManager.h"
#import <AVOSCloud.h>
#import "UMSocial.h"
#import <LeanCloudSocial/AVOSCloudSNS.h>

@interface AppDelegate ()<BMKGeneralDelegate>

@end
BMKMapManager *_mapManager;
@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [AVOSCloud setApplicationId:@"e6jgIMjPuBBOs29Ckdy0DPyg"
                      clientKey:@"qFbDVkYp2fRDxda0XbfmQDmD"];

    [AVOSCloud setAllLogsEnabled:YES];
    [AVOSCloud setLastModifyEnabled:YES];
    
    
    //使用百度地图，先启动BaiduMapManger
   _mapManager = [[BMKMapManager alloc]init];
    BOOL ret = [_mapManager start:@"bgK6Rq8vsLof8h47fzYGCd9k"generalDelegate:self];
    if (!ret) {
       // NSLog(@"manager start failed!");
        
    }else{
      //  NSLog(@"BaiduMap manager 已经启动");
        
    }
    
    
     [UMSocialData setAppKey:@"564c5b0267e58eed4f0046b2"];
    
    //1.创建窗口
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    //2.显示窗口
    self.window.backgroundColor = [UIColor whiteColor];
   
    
    self.window.rootViewController = [[LYYTabBarViewController alloc]init];
     [self.window makeKeyAndVisible];
    
    [[UserLocationManager sharedInstance] startLocation];

    
    return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [AVOSCloudSNS handleOpenURL:url];
}
//实现generalDelegate的代理方法

- (void)onGetNetworkState:(int)iError
{
    if (0 == iError) {
//        NSLog(@"联网成功");
    }
    else{
//        NSLog(@"onGetNetworkState %d",iError);
    }
    
}

-(void)onGetPermissionState:(int)iError{

    if (0 == iError) {
//        NSLog(@"baidu map api -----------授权成功");
        
    }else {
    
//        NSLog(@"baidu map api -----------onGetPermissionState %d",iError);

    }


}
- (void)applicationWillResignActive:(UIApplication *)application {
    
//    [BMKMapView willBackGround];//百度地图API

}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    
//    [BMKMapView willBackGround];//百度地图API
    
    
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
